<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>考试已结束</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f4f4f4;
            margin: 0;
            padding: 0;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
        }

        .container {
            background-color: white;
            padding: 2rem;
            border-radius: 8px;
            box-shadow: 0 0 15px rgba(0, 0, 0, 0.1);
            width: 100%;
            max-width: 400px;
            text-align: center;
        }

        h1 {
            font-size: 2rem;
            margin-bottom: 1.5rem;
            color: #007bff;
        }

        p {
            font-size: 1.25rem;
            color: #333;
            margin-bottom: 1rem;
        }

        .error {
            color: red;
            font-weight: bold;
        }

        .btn {
            display: inline-block;
            padding: 0.75rem 1.5rem;
            font-size: 1rem;
            color: white;
            background-color: #007bff;
            border-radius: 4px;
            text-decoration: none;
            margin-top: 2rem;
            transition: background-color 0.3s ease;
        }

        .btn:hover {
            background-color: #0056b3;
        }

        .btn-secondary {
            background-color: #6c757d;
        }

        .btn-secondary:hover {
            background-color: #5a6268;
        }

        .auto-redirect {
            font-size: 0.9rem;
            color: #666;
            margin-top: 1rem;
        }

    </style>
</head>
<body>
    <div class="container">
        <h1>考试已结束</h1>

        {% if error %}
            <p class="error">考试提交过程中发生错误: {{ error }}</p>
        {% else %}
            <p>您已完成考试: <strong>{{ exam_name }}</strong></p>
            <p>考试用时: <strong>{{ elapsed_seconds // 60 }} 分钟 {{ elapsed_seconds % 60 }} 秒</strong></p>
        {% endif %}

        <a href="{{ url_for('student_class', username=username, class_name=class_name) }}" class="btn">返回加入考试页面</a>
        <a href="{{ url_for('student_dashboard', username=username) }}" class="btn btn-secondary">返回主页面</a>

        <p class="auto-redirect">页面将在 <span id="countdown">10</span> 秒后自动跳转到加入考试页面。</p>
    </div>

    <script>
        // 自动跳转倒计时功能
        var countdownElement = document.getElementById('countdown');
        var countdown = 10;
        var redirectUrl = "{{ url_for('student_class', username=username, class_name=class_name) }}";

        function updateCountdown() {
            countdown -= 1;
            countdownElement.textContent = countdown;

            if (countdown <= 0) {
                window.location.href = redirectUrl;
            }
        }

        setInterval(updateCountdown, 1000);
    </script>
</body>
</html>
